#include "stdafx.h"

#include "moonNameBoard.h"

namespace moon
{
NameBoard::NameBoard(const String &name, const std::wstring &caption)
: m_bShow(true), m_bShowName(true), m_bShowTitle(true)
, m_BgrOffsetH(0.0025f), m_BgrOffsetV(-0.0025f), m_BgrOffsetD(0.00f)
, m_NameText( name, caption )
//, m_NameTextBgr( name+"_Bgr", caption,  0.01f )
, m_pTitleIcon( NULL )
{
	//m_NameTextBgr.setAdditionalHeight( m_BgrOffsetV );
 	//m_NameTextBgr.setLocalTranslation( Ogre::Vector3( m_BgrOffsetH, 0.f, m_BgrOffsetD ) );
}

NameBoard::~NameBoard()
{
	if( m_pTitleIcon )
	{
		delete m_pTitleIcon;
		m_pTitleIcon = NULL;
	}
}

void NameBoard::showTitleIcon(Ogre::String name, Ogre::String fileName
							  , float height, float width, float addHeight, float left )
{
	if( m_pTitleIcon )
	{
		delete m_pTitleIcon;
		m_pTitleIcon = NULL;
	}
//	float offsetX = (left - width/2);
	m_pTitleIcon = new Ogre::MovableTexture( name, fileName, height, width, left );
	m_pTitleIcon->setAdditionalHeight( addHeight );
	m_pTitleIcon->setVisible( true );
//	Ogre::Vector3 vec = m_pTitleIcon->getGlobalTranslation();
	
	//m_pTitleIcon->setGlobalTranslation( vec );
	
}


 
void NameBoard::setAdditionalHeight( Real height )
{
	//m_NameText.setAdditionalHeight( height );
	//m_NameTextBgr.setAdditionalHeight( height + m_BgrOffsetV );
}



void NameBoard::setTextVisible( bool bVisible )
{
	//m_NameText.setVisible( bVisible );
	//m_NameTextBgr.setVisible( bVisible );
}

void NameBoard::setTextColor( const Ogre::ColourValue &color )
{
//	m_NameText.setTextColor(color);
}

void NameBoard::setTextBgrColor( const Ogre::ColourValue &color )
{
	//m_NameTextBgr.setTextColor( color );
}

void NameBoard::setTextBgrOffsetPos( float OffsetH, float OffsetV, float OffsetD )
{
	m_BgrOffsetH = OffsetH;
	m_BgrOffsetV = OffsetV;
	m_BgrOffsetD = OffsetD;
	//m_NameTextBgr.setAdditionalHeight( OffsetV );
	//m_NameTextBgr.setLocalTranslation( Ogre::Vector3( m_BgrOffsetH, 0.f, m_BgrOffsetD ) );
}

void NameBoard::setAutoScale(bool bAutoScale, float scaleK )
{
	//if(scaleK < 0.f)
	//	scaleK = 0.1f;
	//this->m_NameText.setAutoScale( bAutoScale, scaleK );
	//this->m_NameTextBgr.setAutoScale( bAutoScale, scaleK );
}

void NameBoard::setIconAutoScale(bool bAutoScale, float scaleK )
{
	if(scaleK < 0.f)
		scaleK = 0.1f;
	if(!m_pTitleIcon)
		return;
	m_pTitleIcon->setAutoScale( bAutoScale, scaleK );
}


void NameBoard::attachText2Obj( Ogre::SceneNode * pNode )
{
	//pNode->attachObject( &m_NameText);
//	pNode->attachObject( &m_NameTextBgr);
}
 
void NameBoard::attachText2Bone( Ogre::Entity * pEntity, Ogre::String &boneName )
{
	m_NameText.setAvatar(pEntity ,boneName);
	//pEntity->attachObjectToBone( boneName, &m_NameText );
	//pEntity->attachObjectToBone( boneName, &m_NameTextBgr );
}

void	NameBoard::detachText2Bone( Ogre::Entity * pEntity )
{
	//MovableObject * df = static_cast<MovableObject *>(&m_NameText);
	//pEntity->detachObjectFromBone(df->getName());
}
void	NameBoard::detachIcon2Bone( Ogre::Entity * pEntity )
{
	if (m_pTitleIcon)
	{
		MovableObject * df = static_cast<MovableObject *>(m_pTitleIcon);
		pEntity->detachObjectFromBone(df->getName());
	}
	
}

void NameBoard::attachIcon2Obj( Ogre::SceneNode * pNode )
{
	if( m_pTitleIcon )
		pNode->attachObject( m_pTitleIcon );
}

void NameBoard::attachIcon2Bone( Ogre::Entity * pEntity, Ogre::String &boneName )
{
	if( m_pTitleIcon )
		pEntity->attachObjectToBone( boneName, m_pTitleIcon );
}

float NameBoard::getTextLen()
{
	return 0;
	//return m_NameText.getLen();
}

void NameBoard::updata()
{
	m_NameText.updata();
}
}//namespace moon